﻿@using MML.Helpers.Knockout;
@model AppSCO.Models.administracionModel
@{
    ViewBag.Title = "citasGeneradas";
    var ko = Html.CreateKnockoutContext();
}

<h1>CITAS ONLINE GENERADAS</h1>

<table class="grilla" style="width:98%;">
    <thead>
        <tr>
            <th>DNI</th>
            <th>PACIENTE</th>
            <th>SEXO</th>
            <th>CELULAR</th>
            <th>CORREO</th>
            <th>FECHA CITA</th>
            <th>HORARIO</th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody data-bind="foreach: citasGeneradas">
        <tr>
            <td><span data-bind="text: DNIPAC"></span></td>
            <td><span data-bind="text: NOMPAC"></span>&nbsp;<span data-bind="text: APEPPAC"></span>&nbsp;<span data-bind="text: APEMPAC"></span></td>
            <td><span data-bind="text: SEXPAC"></span></td>
            <td><span data-bind="text: TELCPAC"></span></td>
            <td><span data-bind="text: CORPAC"></span></td>
            <td><span data-bind="text: FECCITA"></span></td>
            <td><span data-bind="text: DESHOR"></span></td>
            <td>
                <button data-bind="click: function() { viewModel.atenderCita($data); }">ATENDER</button>&nbsp;
                <button data-bind="click: function() { viewModel.cancelarCita($data); }">CANCELAR</button>
            </td>
        </tr>
    </tbody>
    <tfoot data-bind="visible: viewModel.dontResult">
        <tr>
            <td colspan="10">NO SE ENCONTRARON HORARIOS DISPONIBLES</td>
        </tr>
    </tfoot>
</table><br />

@ko.Initialize(Model)
<script type="text/javascript">
    var urlCitasGeneradas = '@Url.Action("listaCitasGeneradas","citas")';
    var urlAtencionCita = '@Url.Action("atencionCitas","atencion")';
    var urlCancelarCita = '@Url.Action("cancelacionCitas","atencion")';

    viewModel.dontResult = ko.observable(true);
    viewModel.verCitasGeneradas = function () {
        $.ajax({
            url: urlCitasGeneradas,
            type: "POST",
            async: true,
            data: "{ 'FLGEST' : 'G', 'Index': '1' }",
            contentType: "application/json",
            success: function (result) {
                ko.mapping.fromJS(result.datos, {}, viewModel.citasGeneradas);
                if (result.datos != null)
                    viewModel.dontResult(false);
            },
            error: msgError
        });
    }

    viewModel.atenderCita = function (data) {
        document.location = urlAtencionCita + "?CODCIT=" + data.CODCIT();
    }

    viewModel.cancelarCita = function (data) {
        document.location = urlCancelarCita + "?CODCIT=" + data.CODCIT();
    }

    $(document).ready(function () {
        //alert(viewModel.dontResult());
        viewModel.verCitasGeneradas();
    });

</script>
@ko.Apply(Model)